package cn.xf.dao;

import cn.xf.domain.Orders;
import cn.xf.domain.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author xiaofu
 * @date 2021-05-14 12:20
 * @email dearaf@163.com
 */

public interface IOrdersDao {
    /**
     * 分页查询所有订单
     * @return
     */
    @Select("select * from orders")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "peopleCount", property = "peopleCount"),
            @Result(column = "payType", property = "payType"),
            @Result(column = "orderDesc", property = "orderDesc"),
            @Result(column = "productId", property = "product",
                    one = @One(select = "cn.xf.dao.IProductDao.findById"))})
    List<Orders> findAllByPage();


    /**
     * 分页   根据订单ID查询所有订单
     * 一对一指定column：为订单表中对应的其对象外键ID
     * 一对多指定column：为对应的属性数据库中ID
     * @return
     */
    @Select("select * from orders where id=#{id}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "peopleCount", property = "peopleCount"),
            @Result(column = "payType", property = "payType"),
            @Result(column = "orderDesc", property = "orderDesc"),
            @Result(column = "productId", property = "product",javaType = Product.class,
                    one = @One(select = "cn.xf.dao.IProductDao.findById")),
            @Result(column = "memberId", property = "member",javaType = Orders.class,
                    one = @One(select = "cn.xf.dao.IMemberDao.findById")),
            @Result(column = "id", property = "travellers",javaType = java.util.List.class,
            many = @Many(select = "cn.xf.dao.ITravellerDao.findByOrdersId"))})
    Orders findById(String id);


    /**
     * 分页查询所有订单
     * @return
     */
    @Select("select * from orders where productId = #{productId}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "peopleCount", property = "peopleCount"),
            @Result(column = "payType", property = "payType"),
            @Result(column = "orderDesc", property = "orderDesc"),
            @Result(column = "productId", property = "product",
                    one = @One(select = "cn.xf.dao.IProductDao.findById"))})
    List<Orders> findByProductId(String productId);
}
